package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.service.FileService;
import com.hotelvip.vo.ImageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传
 * @author Lzh
 * @date 2021/1/22 11:11
 */

@RestController
@RequestMapping("/upload")
@Api(basePath = "/upload", tags = "文件上传模块")
public class FiledUploadController {
    @Autowired
    private FileService filedService;

    /**
     *
     * @param file 上传的文件
     * @return url地址
     */
    @ApiOperation(value = "协议文件上传", httpMethod = "POST")
    @PostMapping("/picUpload")
    public JSONResult agreementUpload(MultipartFile file) {
        ImageVO upload = filedService.upload(file);
        if (upload.getError()!=0){
            return JSONResult.errorMsg("文件上传失败");
        }
        return JSONResult.ok(upload,"文件上传成功");
    }
}
